package com.ruoyi.hippocampus.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.hippocampus.domain.RoleMenu;
import com.ruoyi.hippocampus.service.IRoleMenuService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 角色-权限管理Controller
 * 
 * @author ruoyi
 * @date 2023-07-05
 */
@RestController
@RequestMapping("/hippocampus/rolemenu")
public class RoleMenuController extends BaseController
{
    @Autowired
    private IRoleMenuService roleMenuService;

    /**
     * 查询角色-权限管理列表
     */
    @PreAuthorize("@ss.hasPermi('hippocampus:rolemenu:list')")
    @GetMapping("/list")
    public TableDataInfo list(RoleMenu roleMenu)
    {
        startPage();
        List<RoleMenu> list = roleMenuService.selectRoleMenuList(roleMenu);
        return getDataTable(list);
    }

    /**
     * 导出角色-权限管理列表
     */
    @PreAuthorize("@ss.hasPermi('hippocampus:rolemenu:export')")
    @Log(title = "角色-权限管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RoleMenu roleMenu)
    {
        List<RoleMenu> list = roleMenuService.selectRoleMenuList(roleMenu);
        ExcelUtil<RoleMenu> util = new ExcelUtil<RoleMenu>(RoleMenu.class);
        util.exportExcel(response, list, "角色-权限管理数据");
    }

    /**
     * 获取角色-权限管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('hippocampus:rolemenu:query')")
    @GetMapping(value = "/{roleId}")
    public AjaxResult getInfo(@PathVariable("roleId") Long roleId)
    {
        return AjaxResult.success(roleMenuService.selectRoleMenuByRoleId(roleId));
    }

    /**
     * 新增角色-权限管理
     */
    @PreAuthorize("@ss.hasPermi('hippocampus:rolemenu:add')")
    @Log(title = "角色-权限管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RoleMenu roleMenu)
    {
        return toAjax(roleMenuService.insertRoleMenu(roleMenu));
    }

    /**
     * 修改角色-权限管理
     */
    @PreAuthorize("@ss.hasPermi('hippocampus:rolemenu:edit')")
    @Log(title = "角色-权限管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RoleMenu roleMenu)
    {
        return toAjax(roleMenuService.updateRoleMenu(roleMenu));
    }

    /**
     * 删除角色-权限管理
     */
    @PreAuthorize("@ss.hasPermi('hippocampus:rolemenu:remove')")
    @Log(title = "角色-权限管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{roleIds}")
    public AjaxResult remove(@PathVariable Long[] roleIds)
    {
        return toAjax(roleMenuService.deleteRoleMenuByRoleIds(roleIds));
    }
}
